title: AVAsset Reader / Writer / Export description: New low-level companions to AVAsset: AVAssetExportSession (preset-based transcode), AVAssetReader + Video/AudioOutput (pull decoded frames as UIImage / interleaved Float32 PCM), and AVAssetWriter + AVAssetWriterInput (push frames / samples to mp4 / m4a). Suitable for transcoding, OCR / ML on individual frames, waveform / FFT, and synthesizing media from JS. tag: PRO
Three lower-level companions to AVAsset, mirroring the iOS AVAssetExportSession / AVAssetReader / AVAssetWriter APIs:
AVAssetExportSession— high-level transcoding / re-encoding with a preset name.AVAssetReader+ outputs — pull decoded video frames asUIImageor PCM audio asFloat32Array.AVAssetWriter+AVAssetWriterInput— push frames / samples produced in JS into a new mp4 / m4a file.
Local files only. Both
AVAssetReaderandAVAssetExportSessionare unreliable when fed an HTTP-streamed asset. Download remote sources to a local path first (fetch()+FileManager.writeAsBytes()), then construct the asset from that path.
AVAssetExportSession
High-level transcode / re-encode using a preset.
Constructor
new AVAssetExportSession(asset: AVAsset, presetName: AVAssetExportPreset)
Throws if asset is not a non-disposed AVAsset. The preset's compatibility with the asset is validated lazily inside exportTo().
Properties
Methods
exportTo(outputPath: string): Promise<void>
Resolves on success, rejects with the underlying session.error.localizedDescription on failure (including the cancellation case). Calling while another export is running rejects immediately.
If outputFileType is incompatible with the preset, the promise rejects with a list of supported types — it does not throw an uncatchable ObjC NSInvalidArgumentException.
cancel(): void
Cancels the in-flight export. The pending exportTo promise rejects with "Export cancelled.".
dispose(): void
Releases the underlying session.
AVAssetReader
Pull decoded samples from an asset, frame-by-frame or chunk-by-chunk.
AVAssetReader
AVAssetReaderVideoOutput
copyNextFrame() returns null only on a clean end-of-stream. If the reader transitions to 'failed' or 'cancelled', the promise rejects so you don't silently see "0 frames decoded".
AVAssetReaderAudioOutput
Always interleaved 32-bit float PCM. Pass multiple tracks to mix; options.sampleRate and options.channels resample / re-channel.
AVAssetWriter
Manually push UIImage frames or PCM chunks to produce a new mp4 / m4a.
